import { Controller } from "../../mvc/core/Controller";
import { ChatHintIconView } from "../view/chat/chatPrivate/ChatHintIconView";
import { ChatModule } from "../../../modules/ChatModule";
import { ChatType } from "../view/chat/chatViewData/ChatType";
import { ChatArea } from "../view/chat/ChatArea";
import { SystemSetter } from "../view/system/SystemSetter";
import { IView } from "../../mvc/interfaces/IView";
import { LayerManager } from "../manager/LayerManager";
import { Dispatcher } from "../../mvc/core/Dispatcher";
import { EventName } from "../mvc/EventName";
import { NetDispatcher } from "../../mvc/core/NetDispatcher";
import { ServerCommand } from "../mvc/ServerCommand";
import { EPublicCommand } from "../../../Message/Command/EPublicCommand";
import { DataEvent } from "../events/DataEvent";
import { GameProxy } from "../mvc/GameProxy";
import { ChatPublicCrossWindow } from "../view/chat/chatCross/ChatPublicCrossWindow";
import { GameMapUtil } from "../scene/map/GameMapUtil";
import { RolePlayer } from "../scene/player/entity/RolePlayer";
import { ChatManager } from "../view/chat/chatPrivate/ChatManager";
import { EChatType } from "../../../Message/Public/EChatType";
import { MessageBlock } from "../../../Framework/MQ/MessageBlock";
import { SDominionChatPlayerInfos } from "../../../Message/Public/SDominionChatPlayerInfos";
import { UnionChatPannel } from "../view/dominionWar/beacon/UnionChatPannel";
import { Cache } from "../cache/Cache";
import { Language } from "../../../extend/language/Language";
import { ParamsConst } from "../../common/global/ParamsConst";
import { ChatFraudFilter } from "../../../com/gengine/utils/ChatFraudFilter";
import { SPublicMiniPlayer } from "../../../Message/Public/SPublicMiniPlayer";
import { PlayerMiniInfo } from "../model/PlayerMiniInfo";
import { MsgManager } from "../manager/MsgManager";
import { EChatTypeEx } from "../../../Message/Public/EChatTypeEx";
import { ChatMessageWorking } from "../view/chat/chatViewData/ChatMessageWorking";
import { EPlayerItemPosType } from "../../../Message/Public/EPlayerItemPosType";
import { ChatPrivateData } from "../view/chat/chatPrivate/ChatPrivateData";
import { EntityUtil } from "../scene/layer/utils/EntityUtil";
import { ChatGuildWindow } from "../view/chat/chatGuild/ChatGuildWindow";
import { ItemData } from "../resource/info/ItemData";
import { SPetInfo } from "../../../Message/Game/SPetInfo";
import { ChatShowPoint } from "../view/chat/data/ChatShowPoint";
import { SChatMsg } from "../../../Message/Game/SChatMsg";
import { EFriendFlag } from "../../../Message/Game/EFriendFlag";
import { FaceAuthority } from "../view/chat/data/FaceAuthority";
import { SPlayerItem } from "../../../Message/Public/SPlayerItem";
import { ThingUtil } from "../scene/layer/utils/ThingUtil";
import { GameController } from "../mvc/GameController";
import { SPublicNotice } from "../../../Message/Public/SPublicNotice";
import { ChatStyle } from "../view/chat/chatPanel/ChatStyle";
type int = number;
//class ChatController
    
    export  class ChatController extends Controller
    {
        constructor()
        {
            
            super();this._chatHintIconView = ChatHintIconView.instance();
            this._sendItemList = new Array<any>();
            this._sendPetList = new Array<any>();
            this._sendMapPoint = new Array<any>();
            this._lastSendItemList = new Array<any>();
            this._lastSendPetList = new Array<any>();
            this._lastChatShowPointList = new Array<any>();
            return;
        }

        public addBackStageMsg(arg1: string, arg2: Array<any>=null): void
        {
            if (!arg2) 
            {
                arg2 = [];
            }
            (view as ChatModule).updateTipMsg(ChatType.System, arg1, ChatArea.Complex, 1, arg2);
            return;
        }

        public addTypeRumorMsg(arg1: string, arg2: Array<any>, arg3: string=null): void
        {
            if (!arg3) 
            {
                arg3 = ChatType.Legent;
            }
            if (!SystemSetter.currentSetter.hideSysBroadcast || !(arg3 == ChatType.Legent)) 
            {
                (view as ChatModule).addRumorMsg(arg1, arg2, arg3);
            }
            return;
        }

        public addCopyMsg(arg1: string, arg2: Array<any>): void
        {
            if (!cache.group.players.length) 
            {
                (view as ChatModule).addCopyMsg(arg1, arg2);
            }
            return;
        }

        public addCrossCopyMsg(arg1: Boolean, arg2: string, arg3: Array<any>): void
        {
            if (!cache.crossGroup.isInGroup || arg1) 
            {
                (view as ChatModule).addCrossCopyMsg(arg2, arg3);
            }
            return;
        }

        public get hintIconView(): ChatHintIconView
        {
            return this._chatHintIconView;
        }

        protected /* override */ initView(): IView
        {
            if (this._chatModule == null) 
            {
                this._chatModule = new ChatModule();
                this._chatModule.x = 0;
                this._chatModule.layer = LayerManager.uiLayer;
            }
            return this._chatModule;
        }

        protected /* override */ initServer(): void
        {
            Dispatcher.addEventListener(EventName.ChatSend, this.sendChatHandler);
            Dispatcher.addEventListener(EventName.ChatPrivate, this.chatPrivateHandler);
            Dispatcher.addEventListener(EventName.ChatPrivateSend, this.sendchatPrivateHandler);
            Dispatcher.addEventListener(EventName.ChatShowItem, this.chatShowHandler);
            Dispatcher.addEventListener(EventName.ChatShowPet, this.chatShowPetHandler);
            Dispatcher.addEventListener(EventName.ChatShowPoint, this.chatShowPointHandler);
            Dispatcher.addEventListener(EventName.ChatShield, this.shieldHandler);
            Dispatcher.addEventListener(EventName.ChatCopyUpRecord, this.copyUpRecordHandler);
            Dispatcher.addEventListener(EventName.ChatSearchPet, this.searchPetHandler);
            Dispatcher.addEventListener(EventName.GuildGetMyInfoSuccess, this.onGuildInfoUpdate);
            Dispatcher.addEventListener(EventName.GuildGetPlayerListSuccess, this.onGuildPlayerListUpdate);
            Dispatcher.addEventListener(EventName.GuildQuitSuccess, this.onGuildQuitSuccessHandler);
            Dispatcher.addEventListener(EventName.GuildDisbandSuccess, this.onGuildQuitSuccessHandler);
            Dispatcher.addEventListener(EventName.ChatGuildDice, this.onChatGuildDice);
            Dispatcher.addEventListener(EventName.OpenDominionChat, this.onDominionChat);
            Dispatcher.addEventListener(EventName.ChatPublicCrossGetSecenePlayersList, this.onGetPublicCrossSecenePlayerList);
            Dispatcher.addEventListener(EventName.ChatPublicCrossSeceneGetPlayersListSuccess, this.onGetPublicCrossSecenePlayersListSuccess);
            Dispatcher.addEventListener(EventName.Scene_Update, this.onSceneUpdateHandler);
            Dispatcher.addEventListener(EventName.ChatPublicCrossSearchPlayerInfo, this.onChatPublicCrossSearchPlayerInfo);
            Dispatcher.addEventListener(EventName.ChatPublicCrossSearchPlayerInfoSuccess, this.onChatPublicCrossSearchPlayerInfoSuccess);
            Dispatcher.addEventListener(EventName.GuildUnionUpdateChatChanel, this.onGuildUnionActiveChange);
            NetDispatcher.addCmdListener(ServerCommand.ChatMessageUpdate, this.chatMessageHandler);
            NetDispatcher.addCmdListener(ServerCommand.GuildNoticeUpdate, this.guildNoticeHandler);
            NetDispatcher.addCmdListener(ServerCommand.EntityInfo_Update, this.setDefaultChatChannel);
            NetDispatcher.addCmdListener(ServerCommand.SearchPlayerResult, this.playeMiniInfoUpdate);
            NetDispatcher.addCmdListener(ServerCommand.Group_EnterOrLeaveGroup, this.onGroupChange);
            NetDispatcher.addCmdListener(ServerCommand.CrossGroup_PlayerInfoChange, this.onGroupChange);
            NetDispatcher.addCmdListener(ServerCommand.VIPInfoUpdateCommand, this.onUpdateVIP);
            NetDispatcher.addCmdListener(EPublicCommand._ECmdPublicChatMsgDominionPlayerInfo, this.onDomChatList);
            return;
        }

        /* internal  */onGetPublicCrossSecenePlayerList(arg1: DataEvent): void
        {
            GameProxy.chatProxy.getScenePlayersInfo();
            return;
        }

        /* internal  */onGetPublicCrossSecenePlayersListSuccess(arg1: DataEvent): void
        {
            var loc1=arg1.data as Array<any>;
            ChatPublicCrossWindow.instance.updateMemberList(loc1);
            return;
        }

        /* internal  */onSceneUpdateHandler(arg1: DataEvent): void
        {
            (view as ChatModule).changeTabBar();
            if (GameMapUtil.curMapState.isCrossMap && !RolePlayer.instance.isInVideo) 
            {
                this.inCrossMaped = true;
                (view as ChatModule).addPublicCrossWindow();
                ChatPublicCrossWindow.instance.clearChatInfo();
                Dispatcher.dispatchEvent(new DataEvent(EventName.ChatPublicCrossGetSecenePlayersList));
            }
            else if (this.inCrossMaped) 
            {
                this.hintIconView.removeIcon(ChatPublicCrossWindow.instance.icon);
                ChatPublicCrossWindow.instance.icon.removeAllCall();
                ChatPublicCrossWindow.instance.visible = false;
                ChatManager.closeAllOtherSeverChatWindw(this.hintIconView);
            }
            return;
        }

        /* internal  */onChatPublicCrossSearchPlayerInfo(arg1: DataEvent): void
        {
            var loc1=arg1.data as string;
            GameProxy.chatProxy.findCross(loc1);
            return;
        }

        /* internal  */onChatPublicCrossSearchPlayerInfoSuccess(arg1: DataEvent): void
        {
            var loc1=arg1.data as Array<any>;
            ChatPublicCrossWindow.instance.updatePlayerInfo(loc1);
            return;
        }

        /* internal  */onDominionChat(arg1: DataEvent): void
        {
            GameProxy.chatProxy.getDominionChatList();
            return;
        }

        /* internal  */searchPetHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data["playerId"];
            var loc2=arg1.data["petUid"];
            GameProxy.petProxy.getPetInfo(loc1, loc2);
            return;
        }

        /* internal  */copyUpRecordHandler(arg1: DataEvent): void
        {
            if (this._lastChatContent) 
            {
                this._chatModule.addInputText(this._lastChatContent);
                (view as ChatModule).setChatInputFocus();
                this._sendItemList.splice(0);
                this._sendItemList = this._sendItemList.concat(this._lastSendItemList);
                this._sendPetList.splice(0);
                this._sendPetList = this._sendPetList.concat(this._lastSendPetList);
                this._sendMapPoint.splice(0);
                this._sendMapPoint = this._sendMapPoint.concat(this._lastChatShowPointList);
            }
            return;
        }

        /* internal  */onChatGuildDice(arg1: DataEvent): void
        {
            GameProxy.chatProxy.SendMessage(EChatType._EChatTypeGuildRoll, "1");
            return;
        }

        /* internal  */onDomChatList(arg1: MessageBlock): void
        {
            var loc1=arg1.messageBase as SDominionChatPlayerInfos;
            UnionChatPannel.instance.updateMemberList(loc1.chatPlayers);
            return;
        }

        /* internal  */sendChatHandler(arg1: DataEvent): void
        {
            var loc7=0;
            var loc10=null;
            var loc11=null;
            var loc12=null;
            var loc13=false;
            var loc14=null;
            var loc15=null;
            var loc16=null;
            var loc17=null;
            var loc18=null;
            var loc19=null;
            var loc20=null;
            var loc21=null;
            var loc1=arg1.data;
            var loc2=loc1["area"];
            var loc3=loc1["content"];
            var loc4=0;
            var loc5=this.getChatTypeByArea(loc2);
            var loc6=[];
            if (loc1.hasOwnProperty("color")) 
            {
                loc4 = loc1["color"];
            }
            if (loc2 == ChatArea.World && Cache.instance.role.entityInfo.level < 10) 
            {
                this.addTipMsg(Language.getString(40600), ChatType.Tips);
                return;
            }
            if (loc2 == ChatArea.Scene && Cache.instance.role.entityInfo.level < 20) 
            {
                this.addTipMsg(Language.getString(40688), ChatType.Tips, ChatArea.Scene);
                return;
            }
            if (loc2 == ChatArea.World || loc2 == ChatArea.Country || loc2 == ChatArea.Union || loc2 == ChatArea.Team || loc2 == ChatArea.Scene) 
            {
                if (this._lastChatContent != loc3) 
                {
                    this._lastChatRepeatTime = 0;
                }
                else 
                {
                    var loc22;
                    var loc23=((loc22 = this)._lastChatRepeatTime + 1);
                    loc22._lastChatRepeatTime = loc23;
                }
                if (this._lastChatRepeatTime >= 5) 
                {
                    this.addTipMsg(Language.getString(40601), ChatType.Tips, loc2);
                    (view as ChatModule).clearCD();
                    return;
                }
                this._lastChatContent = loc3;
                this._lastSendItemList.splice(0);
                this._lastSendItemList = this._lastSendItemList.concat(this._sendItemList);
                this._lastSendPetList.splice(0);
                this._lastSendPetList = this._lastSendPetList.concat(this._sendPetList);
                this._lastChatShowPointList.splice(0);
                this._lastChatShowPointList = this._lastChatShowPointList.concat(this._sendMapPoint);
            }
            var loc8=false;
            if (cache.role.entityInfo.level < ParamsConst.instance.chatLimitLevel) 
            {
                if (this.hasUrl(loc3)) 
                {
                    loc8 = true;
                }
                else 
                {
                    loc8 = (loc2 == ChatArea.World || loc2 == ChatArea.Country || loc2 == ChatArea.Speaker) && this.hasQQInfo(loc3);
                }
            }
            if ((loc8 || ChatFraudFilter.isChatFraud(loc3)) && !(cache.title.isGM || cache.title.isGuide)) 
            {
                (loc10 = new SPublicMiniPlayer()).name = cache.role.entityInfo.name;
                loc10.sex = cache.role.entityInfo.sex;
                loc10.camp = cache.role.entityInfo.camp;
                loc10.level = cache.role.entityInfo.level;
                loc10.entityId = cache.role.entityInfo.entityId;
                (view as ChatModule).updateChatMesssage(loc2, new PlayerMiniInfo(loc10), "：" + loc3, [], [], -1, null);
                (view as ChatModule).clearInput();
                this._sendItemList = new Array<any>();
                this._sendPetList = new Array<any>();
                this._sendMapPoint = new Array<any>();
                return;
            }
            if (loc2 == ChatArea.Team) 
            {
                if (!cache.copy.isInCopy && !cache.group.isInGroup) 
                {
                    MsgManager.showRollTipsMsg(Language.getString(40602));
                    return;
                }
            }
            if (loc2 == ChatArea.Union && !cache.guild.myGuildInfo) 
            {
                MsgManager.showRollTipsMsg(Language.getString(40603));
                return;
            }
            var loc9=0;
            if (loc3 != "") 
            {
                loc11 = new Array<any>();
                loc12 = new Array<any>();
                if (this._sendItemList.length > 0) 
                {
                    loc22 = 0;
                    loc23 = this._sendItemList;
                    for(loc14 of loc23) 
                    {
                        if (loc9 >= this.chatShowItemMaxNum) 
                        {
                            break;
                        }
                        loc15 = "[" + loc14.name + "]";
                        if (!((loc7 = loc3.indexOf(loc15)) >= 0)) 
                        {
                            continue;
                        }
                        loc16 = "[" + loc14.posType.toString() + "," + loc14.uid + "]";
                        loc6.push(EChatTypeEx._EChatTypeExShow);
                        loc3 = loc3.replace(loc15, loc16);
                        ++loc9;
                    }
                }
                if (this._sendPetList.length > 0) 
                {
                    loc22 = 0;
                    loc23 = this._sendPetList;
                    for(loc17 of loc23) 
                    {
                        if (loc9 >= this.chatShowItemMaxNum) 
                        {
                            break;
                        }
                        loc18 = ChatMessageWorking.getPetName(loc17);
                        loc18 = "[" + loc18 + "]";
                        if (!((loc7 = loc3.indexOf(loc18)) >= 0)) 
                        {
                            continue;
                        }
                        loc19 = "[" + EPlayerItemPosType._EPlayerItemPosTypePet + "," + loc17.uid + "]";
                        if (loc6.indexOf(EChatTypeEx._EChatTypeExShow) == -1) 
                        {
                            loc6.push(EChatTypeEx._EChatTypeExShow);
                        }
                        loc3 = loc3.replace(loc18, loc19);
                        loc12.push(loc17);
                        ++loc9;
                    }
                }
                loc13 = false;
                if (this._sendMapPoint.length > 0) 
                {
                    loc22 = 0;
                    loc23 = this._sendMapPoint;
                    for(loc20 of loc23) 
                    {
                        if (!(loc21 = loc20.mapNameString())) 
                        {
                            continue;
                        }
                        if (!((loc7 = loc3.indexOf(loc21)) >= 0)) 
                        {
                            continue;
                        }
                        loc13 = true;
                        loc6.push(EChatTypeEx._EChatTypeExSendPos);
                        loc3 = loc3.replace(loc21, loc20.mapIdString());
                    }
                }
                if (loc13 && !(loc2 == ChatArea.Union || loc2 == ChatArea.Team)) 
                {
                    MsgManager.showRollTipsMsg(Language.getString(40681));
                    return;
                }
                GameProxy.chatProxy.SendMessage(loc5, loc3, loc4, null, loc12, loc6);
                (view as ChatModule).clearInput();
                this._sendItemList = new Array<any>();
                this._sendPetList = new Array<any>();
                this._sendMapPoint = new Array<any>();
            }
            return;
        }

        /* internal  */sendchatPrivateHandler(arg1: DataEvent): void
        {
            var loc6=null;
            var loc1=arg1.data;
            var loc2=loc1["content"];
            var loc3=loc1["toPlayer"];
            var loc4=loc1["color"];
            var loc5=false;
            if (cache.role.entityInfo.level < ParamsConst.instance.chatLimitLevel) 
            {
                loc5 = this.hasQQInfo(loc2);
            }
            if ((loc5 || ChatFraudFilter.isChatFraud(loc2)) && !(cache.title.isGM || cache.title.isGuide) || cache.role.entityInfo.level < ParamsConst.instance.chatPrivateLevel) 
            {
                (loc6 = new ChatPrivateData()).chatColor = loc4;
                loc6.chatWindowName = loc3.playerName;
                loc6.crossFlag = EntityUtil.isSameServerByRole(loc3.entityId);
                loc6.chatWindowEntityId = loc3.entityId;
                loc6.chatFromPlayerName = cache.role.entityInfo.name;
                loc6.date = new Date();
                loc6.content = loc2;
                loc6.faceAuthority = Cache.instance.role.playerInfo.VIP > 0 ? 3 : 1;
                (view as ChatModule).updatePrivateChatMessage(loc6);
                return;
            }
            GameProxy.chatProxy.SendPrivateMessage(loc2, loc3, loc4);
            return;
        }

        /* internal  */chatPrivateHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data as PlayerMiniInfo;
            var loc2=(view as ChatModule).addChatWindow(arg1.data as PlayerMiniInfo);
            loc2.visible = true;
            loc2.show();
            loc2.inputText.setFocus();
            if (EntityUtil.isSameServerByRole(loc1.entityId)) 
            {
                GameProxy.friendsProxy.SearchPlayer(loc1.playerName);
            }
            return;
        }

        /* internal  */playeMiniInfoUpdate(arg1: Object): void
        {
            var loc1=arg1["isFind"];
            var loc2=arg1["player"];
            if (!loc1) 
            {
                return;
            }
            if (loc2) 
            {
                this._chatModule.updateWindowPlayerInfo(new PlayerMiniInfo(loc2));
            }
            return;
        }

        /* internal  */onGroupChange(arg1: Object): void
        {
            (view as ChatModule).changeTabBar();
            return;
        }

        /* internal  */onGuildUnionActiveChange(arg1: DataEvent): void
        {
            (view as ChatModule).changeTabBar();
            return;
        }

        /* internal  */onUpdateVIP(arg1: Object): void
        {
            (view as ChatModule).updateVIPState();
            return;
        }

        /* internal  */onGuildInfoUpdate(arg1: DataEvent): void
        {
            ChatGuildWindow.instance.updateNotice(cache.guild.guildInfo.purpose);
            return;
        }

        /* internal  */onGuildPlayerListUpdate(arg1: DataEvent): void
        {
            ChatGuildWindow.instance.updateMemberList(cache.guild.memberArray);
            return;
        }

        /* internal  */onGuildQuitSuccessHandler(arg1: DataEvent): void
        {
            ChatManager.removeGuildChatWindow();
            return;
        }

        /* internal  */chatShowHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data as ItemData;
            this._sendItemList.push(loc1);
            (view as ChatModule).addInputText("[" + loc1.name + "]");
            (view as ChatModule).setChatInputFocus();
            return;
        }

        /* internal  */chatShowPetHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data as SPetInfo;
            this._sendPetList.push(loc1);
            var loc2=ChatMessageWorking.getPetName(loc1);
            loc2 = "[" + loc2 + "]";
            (view as ChatModule).addInputText(loc2);
            (view as ChatModule).setChatInputFocus();
            return;
        }

        /* internal  */chatShowPointHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data as ChatShowPoint;
            this._sendMapPoint.push(loc1);
            return;
        }

        /* internal  */shieldHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data["isShield"];
            var loc2=arg1.data["label"];
            this.addTipMsg(loc2 + Language.getString(40604) + (loc1 ? Language.getString(40605) : Language.getString(40606)), ChatType.System, ChatMessageWorking.getNameByLabel(loc2));
            return;
        }

        /* internal  */chatMessageHandler(arg1: Object): void
        {
            var loc13=false;
            var loc14=null;
            var loc15=false;
            var loc16=false;
            var loc17=false;
            var loc18=false;
            var loc19=null;
            var loc20=null;
            var loc21=0;
            var loc22=null;
            var loc23=null;
            var loc24=0;
            var loc25=0;
            var loc1=arg1 as SChatMsg;
            var loc2=loc1.chatType;
            var loc3=loc1.chatTypeEx;
            var loc4=loc1.content;
            var loc5=loc1.font;
            var loc6=loc1.fromPlayer;
            var loc7=loc1.chatDt;
            var loc8;
            (loc8 = new PlayerMiniInfo(loc6)).online = true;
            if (loc6.level < ParamsConst.instance.chatLimitLevel && loc1.playerItems.length == 0 && loc1.petInfos.length == 0) 
            {
                if (((loc13 = (loc2 == EChatType._EChatTypeWorld || loc2 == EChatType._EChatTypePrivate || loc2 == EChatType._EChatTypeCamp || loc2 == EChatType._EChatTypeTrumpet) && this.hasQQInfo(loc4)) || ChatFraudFilter.isChatFraud(loc4)) && !(loc1.gmFlag || loc1.guideFlag)) 
                {
                    if (loc2 == EChatType._EChatTypeTrumpet && loc1.fromPlayer.entityId.id == cache.role.entityInfo.entityId.id) 
                    {
                        NetDispatcher.dispatchCmd(ServerCommand.ChatTrumpetMessageUpdate, arg1);
                    }
                    return;
                }
            }
            if (loc2 == EChatType._EChatTypeTrumpet) 
            {
                NetDispatcher.dispatchCmd(ServerCommand.ChatTrumpetMessageUpdate, arg1);
            }
            if (loc1.chatType != EChatType._EChatTypeGuild) 
            {
                if (loc1.extend.length > 0) 
                {
                    loc8.worldPost = loc1.extend[0];
                }
            }
            else 
            {
                if (loc1.extend.length > 0) 
                {
                    loc8.post = loc1.extend[0];
                }
                if (loc1.extend.length > 1) 
                {
                    loc8.worldPost = loc1.extend[1];
                }
            }
            if (loc1.gmFlag) 
            {
                loc8.isGM = true;
            }
            if (loc1.guideFlag) 
            {
                loc8.isGuide = true;
            }
            var loc9=cache.role.entityInfo.name;
            var loc10=cache.friend.getFriendInfoByPlayerName(loc8.playerName, EFriendFlag._EFriendFlagBlackList) ? true : false;
            if (loc2 == EChatType._EChatTypePrivate && !loc10) 
            {
                if (!(loc9 == loc8.playerName) && !(loc9 == loc1.toPlayerName)) 
                {
                    return;
                }
                (loc14 = new ChatPrivateData()).chatFromPlayerName = loc8.playerName;
                loc14.sChatMsg = loc1;
                loc14.date = loc7;
                loc14.content = loc4;
                loc14.chatColor = loc5;
                loc14.sChatMsg = loc1;
                loc14.faceAuthority = FaceAuthority.getMiniPlayerAuthority(loc1.fromPlayer);
                loc14.crossFlag = loc1.crossFlag;
                if (EntityUtil.equal(cache.role.entityInfo.entityId, loc8.entityId)) 
                {
                    loc14.chatWindowName = loc1.toPlayerName;
                    loc14.chatWindowEntityId = loc1.toEntityId;
                    (view as ChatModule).updatePrivateChatMessage(loc14);
                    if ((loc20 = (view as ChatModule).getChatPlayerInfoByName(loc1.toPlayerName)) != null) 
                    {
                        Dispatcher.dispatchEvent(new DataEvent(EventName.FriendPrivateChatRecord, loc20));
                    }
                }
                else 
                {
                    loc15 = cache.personalSetCache.isRefusedToStranger;
                    loc16 = cache.friend.getFriendInfoByPlayerName(loc8.playerName, EFriendFlag._EFriendFlagFriend) ? true : false;
                    loc17 = cache.friend.getFriendInfoByPlayerName(loc8.playerName, EFriendFlag._EFriendFlagEnemy) ? true : false;
                    if (!(loc10 || loc15 && !loc16 && !loc17)) 
                    {
                        (view as ChatModule).addChatWindow(loc8);
                        loc14.chatWindowName = loc8.playerName;
                        loc14.chatWindowEntityId = loc8.entityId;
                        (view as ChatModule).updatePrivateChatMessage(loc14);
                        Dispatcher.dispatchEvent(new DataEvent(EventName.FriendPrivateChatRecord, loc8));
                        loc18 = cache.personalSetCache.isAutoReply;
                        loc19 = cache.personalSetCache.autoReplyText;
                        if (loc18) 
                        {
                            Dispatcher.dispatchEvent(new DataEvent(EventName.ChatPrivateSend, {"content": loc19, "toPlayer": loc8}));
                        }
                    }
                }
            }
            if (loc10) 
            {
                return;
            }
            var loc11=new Array<any>();
            if (loc3.indexOf(EChatTypeEx._EChatTypeExShow) >= 0) 
            {
                loc21 = 0;
                while (loc21 < loc1.playerItems.length) 
                {
                    loc11.push(new ItemData(loc1.playerItems[loc21] as SPlayerItem));
                    ++loc21;
                }
            }
            if (!(loc3.indexOf(EChatTypeEx._EChatTypeExSendPos) >= 0)) 
            {
            };
            var loc12;
            if ((loc12 = this.getNameByChatType(loc2)) == ChatArea.Scene || loc12 == ChatArea.Team) 
            {
                loc22 = ChatMessageWorking.getCellDatas(loc4, loc11, loc1.petInfos, -1, 12, FaceAuthority.getPlayerAuthority(loc8));
                loc23 = "";
                loc24 = 0;
                while (loc24 < loc22.length) 
                {
                    loc23 = loc23 + loc22[loc24].text;
                    ++loc24;
                }
                ThingUtil.entityUtil.entityTalk(loc8.entityId, loc23, loc1.bubbleId);
                if (loc12 == ChatArea.Team) 
                {
                    GameController.gameui.getGameui().teamAvatarSprite.teamTalk(loc8.entityId, loc23, loc1.bubbleId);
                }
            }
            if (!(loc12 == ChatArea.Country && !(loc6.camp == cache.role.entityInfo.camp)) && !(loc2 == EChatType._EChatTypeDominion)) 
            {
                if (loc12 == ChatArea.Union) 
                {
                    (view as ChatModule).addGuildChatWindow();
                    if (loc2 == EChatType._EChatTypeGuildRoll) 
                    {
                        loc25 = int(loc4);
                        loc4 = ChatMessageWorking.getDiceText(loc8.playerName, loc25);
                        (view as ChatModule).updateGuildChatMessage(loc8, loc7, loc4, loc11, loc1.petInfos, loc5, true);
                        return;
                    }
                    (view as ChatModule).updateGuildChatMessage(loc8, loc7, loc4, loc11, loc1.petInfos, loc5);
                }
                if (loc12 == ChatArea.Scene && GameMapUtil.curMapState.isCrossMap) 
                {
                    (view as ChatModule).addPublicCrossWindow();
                    (view as ChatModule).updatePublicCrossChatMessage(loc8, loc7, loc4, loc11, loc1.petInfos, loc5);
                }
                loc4 = "：" + loc4;
                (view as ChatModule).updateChatMesssage(loc12, loc8, loc4, loc11, loc1.petInfos, loc1.force, loc1);
            }
            if (loc2 == EChatType._EChatTypeDominion) 
            {
                UnionChatPannel.instance.addChatItem(loc8, loc7, loc4, loc11, loc1.petInfos, loc5);
            }
            return;
        }

        /* internal  */hasQQInfo(arg1: string): Boolean
        {
            var loc1=ChatFraudFilter.delSpecialSymbols(arg1);
            if (loc1.length >= ParamsConst.instance.chatNumLimit) 
            {
                return true;
            }
            return false;
        }

        /* internal  */hasUrl(arg1: string): Boolean
        {
            var loc1=null;
            arg1 = arg1.replace(new RegExp("\\s", "g"), "");
            if (arg1.length > 20) 
            {
                loc1 = new RegExp("(http|https|ftp|file)?([:\\/]*)([\\w-]{2,}\\.)+([A-Za-z]{2,6})+", "ig");
                return loc1.test(arg1);
            }
            return false;
        }

        /* internal  */guildNoticeHandler(arg1: Object): void
        {
            var loc1=arg1 as SPublicNotice;
            var loc2=loc1.content;
            this.addTipMsg(loc2, ChatType.Union, ChatArea.Union, 2, loc1.publicMiniplayers, ChatStyle.getTitleColor(ChatType.Union));
            return;
        }

        /* internal  */setDefaultChatChannel(arg1: Object): void
        {
            if (Cache.instance.role.entityInfo.level < 10) 
            {
                this._chatModule.setDefaultCountryChannel();
            }
            NetDispatcher.removeCmdListener(ServerCommand.EntityInfo_Update, this.setDefaultChatChannel);
            return;
        }

        /* internal  */getChatTypeByArea(arg1: string): int
        {
            var loc1=EChatType._EChatTypeWorld;
            var loc2=arg1;
            switch (loc2) 
            {
                case ChatArea.World:
                {
                    loc1 = EChatType._EChatTypeWorld;
                    break;
                }
                case ChatArea.Country:
                {
                    loc1 = EChatType._EChatTypeCamp;
                    break;
                }
                case ChatArea.Scene:
                {
                    loc1 = EChatType._EChatTypeSpace;
                    break;
                }
                case ChatArea.Union:
                {
                    loc1 = EChatType._EChatTypeGuild;
                    break;
                }
                case ChatArea.Team:
                {
                    loc1 = EChatType._EChatTypeTeam;
                    break;
                }
                case ChatArea.Secret:
                {
                    loc1 = EChatType._EChatTypePrivate;
                    break;
                }
                case ChatArea.Speaker:
                {
                    loc1 = EChatType._EChatTypeTrumpet;
                    break;
                }
                case ChatArea.Force:
                {
                    loc1 = EChatType._EChatTypeForce;
                    break;
                }
                case ChatArea.CrossGrop:
                {
                    loc1 = EChatType._EChatTypeCrossGroup;
                    break;
                }
                case ChatArea.Group:
                {
                    loc1 = EChatType._EChatTypeGuildGroup;
                    break;
                }
                case ChatArea.GuildUnion:
                {
                    loc1 = EChatType._EChatTypeGuildUnion;
                    break;
                }
                case ChatArea.Dominion:
                {
                    loc1 = EChatType._EChatTypeDominion;
                    break;
                }
            }
            return loc1;
        }

        /* internal  */getNameByChatType(arg1: int): string
        {
            var loc1=ChatArea.World;
            var loc2=arg1;
            switch (loc2) 
            {
                case EChatType._EChatTypeWorld:
                {
                    loc1 = ChatArea.World;
                    break;
                }
                case EChatType._EChatTypeCamp:
                {
                    loc1 = ChatArea.Country;
                    break;
                }
                case EChatType._EChatTypeTeam:
                {
                    loc1 = ChatArea.Team;
                    break;
                }
                case EChatType._EChatTypeGuild: case EChatType._EChatTypeGuildRoll:
                {
                    loc1 = ChatArea.Union;
                    break;
                }
                case EChatType._EChatTypeSpace:
                {
                    loc1 = ChatArea.Scene;
                    break;
                }
                case EChatType._EChatTypePrivate:
                {
                    loc1 = ChatArea.Secret;
                    break;
                }
                case EChatType._EChatTypeTrumpet:
                {
                    loc1 = ChatArea.Speaker;
                    break;
                }
                case EChatType._EChatTypeForce:
                {
                    loc1 = ChatArea.Force;
                    break;
                }
                case EChatType._EChatTypeCrossGroup:
                {
                    loc1 = ChatArea.CrossGrop;
                    break;
                }
                case EChatType._EChatTypeGuildGroup:
                {
                    loc1 = ChatArea.Group;
                    break;
                }
                case EChatType._EChatTypeGuildUnion:
                {
                    loc1 = ChatArea.GuildUnion;
                    break;
                }
                case EChatType._EChatTypeDominion:
                {
                    loc1 = ChatArea.Dominion;
                    break;
                }
            }
            return loc1;
        }

        public addTipMsg(arg1: Object, arg2: string, arg3: string="world", arg4: int=0, arg5: Array<any>=null, arg6: int=16777215): void
        {
            var loc1=arg2;
            switch (loc1) 
            {
                case ChatType.System: case ChatType.Tips: case ChatType.Union: case ChatType.State: case ChatType.Scene: case ChatType.Force: case ChatType.World: case ChatType.CrossServer:
                {
                    (view as ChatModule).updateTipMsg(arg2, arg1 as string, arg3, arg4, arg5, arg6);
                    break;
                }
            }
            return;
        }

        private /* const */chatShowItemMaxNum: int=3;

        private /* var */_chatModule: ChatModule;

        private /* var */_chatHintIconView: ChatHintIconView;

        private /* var */_sendItemList: Array<any>;

        private /* var */_sendPetList: Array<any>;

        private /* var */_sendMapPoint: Array<any>;

        private /* var */_lastChatContent: string;

        private /* var */_lastChatRepeatTime: int=0;

        private /* var */_lastSendItemList: Array<any>;

        private /* var */_lastSendPetList: Array<any>;

        private /* var */_lastChatShowPointList: Array<any>;

        private /* var */haveQQInfoNum: int=0;

        private /* var */inCrossMaped: Boolean=false;
    }
